LazyRowFor is scrollable Container View which organizes his child Views horizontally (next to each other).
You define list of items and Lambda itemContent that is executed for each item (so that you can display them differently).
Syntax
import androidx.compose.foundation.lazy.LazyRowFor
LazyRowFor(
items = listOf("A", "B", "C", "D") + ((0..100).map { it.toString() }),
itemContent = { item ->
when (item) {
"A" -> { Text("ALPHA - ") }
"B" -> { Text("BRAVO - ") }
"C" -> { /* Do Nothing */ }
"D" -> { Text("$item - ") }
else -> { Text("$item - ") }
}
}
)
In this example we create LazyRowFor View with too many Text Views to fit horizontally on the screen.
MainActivity.kt
package com.example.testcompose
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.Text
import androidx.compose.foundation.lazy.LazyRowFor
import androidx.compose.ui.platform.setContent
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
LazyRowFor(
items = listOf("A", "B", "C", "D") + ((0..100).map { it.toString() }),
itemContent = { item ->
when (item) {
"A" -> { Text("ALPHA - ") }
"B" -> { Text("BRAVO - ") }
"C" -> { /* Do Nothing */ }
"D" -> { Text("$item - ") }
else -> { Text("$item - ") }
}
}
)
}
}
}